﻿Imports System.ComponentModel.DataAnnotations
Imports System.Globalization

Namespace Models.Validators

    <AttributeUsage(AttributeTargets.Field Or AttributeTargets.Property, AllowMultiple:=False, Inherited:=True)>
    Public Class ContieneAttribute
        Inherits ValidationAttribute

        Private Property ListString As IEnumerable(Of String)
        Private Const _ErrorMessage As String = "El campo '{0}' no contiene valores validos posible"

        Sub New(lstStrings As String())
            MyBase.New(_ErrorMessage)
            Me.ListString = lstStrings
        End Sub

        Public Overrides Function IsValid(value As Object) As Boolean
            If value Is Nothing Then Return True

            Dim str As String = value
            If String.IsNullOrWhiteSpace(str) Then Return True

            'Verificamos que el valor del usuario se encuentre contenido en alguno de los valores posibles
            Return ListString.Contains(str)
        End Function
    End Class
End Namespace
